<template>
  <div class="box">
    <vue-scroll ref="vs" :ops="$store.state.ops" class="Interrogation_box">
      <div class="Interrogation">
        <div class="title">
          <div class="search_box">
            <el-form :inline="true" ref="form" class="search_form">
              <el-form-item class="search_form_item" label="状态：">
                <el-select v-model="typeValue" placeholder="请选择">
                  <el-option
                    v-for="item in seekMedicalType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item class="search_form_item" label="姓名：">
                <el-input v-model="userName" placeholder="请输入"></el-input>
              </el-form-item>
              <el-form-item class="search_form_item" label="问诊类型：">
                <el-select v-model="orderType" placeholder="请选择">
                  <el-option
                    v-for="item in orderTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item class="search_form_but">
                <div class="search_submitBox cursor" @click="listFun">搜索</div>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="content" v-show="total > 0">
          <el-table :data="tableData">
            <el-table-column prop="patientNameText" width="80" label="姓名">
              <template slot-scope="scope">{{scope.row.patientName | patientNameLength}}</template>
            </el-table-column>
            <el-table-column prop="serviceType" label="问诊类型">
              <template slot-scope="scope">{{scope.row.serviceType | baseServiceTypeFil}}</template>
            </el-table-column>
            <el-table-column prop="patientSex" width="50" label="性别">
              <template slot-scope="scope">{{scope.row.patientSex | baseSexFil}}</template>
            </el-table-column>
            <el-table-column prop="patientAge" width="80" label="患者年龄"></el-table-column>
            <el-table-column prop="phone" width="130" label="联系电话"></el-table-column>
            <el-table-column prop="orderTime" label="日期">
              <template slot-scope="scope">{{scope.row.orderTime | baseTimeMMDDFil}}</template>
            </el-table-column>
            <el-table-column prop="orderStatus" label="状态">
              <template slot-scope="scope">{{scope.row.orderStatus | baseOrderStatusFil}}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <div @click="detailClick(scope.row)" class="submitBtn cursor">查看</div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="noData" v-show="total == 0">
          <img class="noPatientImg" src="/static/img/暂无数据@3x.png" alt />
          <span class="noPatient">暂无数据</span>
        </div>
        <footer class="footer">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            :page-size="10"
            :hide-on-single-page="true"
            :current-page="currentPage"
            @current-change="currentChange"
          ></el-pagination>
        </footer>
      </div>
    </vue-scroll>
    <!-- 视话问诊详情 -->
    <dependingDetsilDialog
      :showTrue="modelType==='dependingDetailDialog'"
      :detail="dependingDetail"
      @close="modelType=''"
    ></dependingDetsilDialog>
  </div>
</template>
<script>
import { getRemoteInterrogationDoctorOrders } from "../../requestApi/depending.js";
import dependingDetsilDialog from "../../components/dialog/dependingDetsilDialog";
import {
  getOrderDetails,
  getOrderInfo,
  doctorStartOrder,
  doctorEndOrder,
  addMedicalHistory,
  queryMedicalHistory
} from "../../requestApi/incompleteCommunication";
import { addRecipeMedicalHistory } from "../../requestApi/prescription";

export default {
  components: { dependingDetsilDialog },
  data() {
    return {
      seekMedicalType: [
        {
          value: false,
          label: "全部"
        },
        {
          value: 5,
          label: "问诊中"
        },
        {
          value: 2,
          label: "待确认"
        },
        {
          value: 3,
          label: "已完成"
        }
      ],
      typeValue: "",
      orderTypeList: [
        {
          value: false,
          label: "全部"
        },
        {
          value: 0,
          label: "系统派单"
        },
        {
          value: 1,
          label: "指定医生"
        }
      ],
      orderType: "",
      userName: "",
      currentPage: 1,
      tableData: [],
      total: 0,
      modelType: "",
      dependingDetail: null
    };
  },
  created: function() {
    window.addEventListener("beforeunload", e => {
      sessionStorage.removeItem("isOpen");
    });
    this.listFun();
  },
  mounted() {
    window.addEventListener("beforeunload", e => {
      sessionStorage.removeItem("isOpen");
    });
  },
  computed: {},
  methods: {
    currentChange(val) {
      let self = this;
      self.currentPage = val;
      self.listFun();
    },
    async listFun() {
      let obj = {
        doctorId: localStorage.getItem("doctorId"),
        pageNo: this.currentPage,
        pageSize: 10
      };
      if (this.typeValue) {
        obj.orderStatus = this.typeValue;
      }
      if (this.userName) {
        obj.patientName = this.userName;
      }
      if (this.orderType !== false && this.orderType !== "") {
        obj.serviceType = this.orderType;
      }
      this.tableData = [];
      let data = await getRemoteInterrogationDoctorOrders(obj);
      if (data.code == 200) {
        if (data.data) {
          this.total = Number(data.data.total) || 0;
          if (Number(data.data.total) > 0) {
            this.tableData = data.data.records;
          }
        }
      }
    },
    /* 获取订单信息  start */
    detailClick(row) {
      let self = this;
      self.detailFun(row.orderId);
    },
    async detailFun(orderId) {
      let self = this;
      let response = await getOrderDetails({
        orderId: orderId
      });
      if (response.code == 200 && response.data) {
        if (response.data.medicalHistoryId) {
          self.queryMedicalHistoryFun(
            response.data.medicalHistoryId,
            response.data
          );
        } else {
          self.modelType = "dependingDetailDialog";
          self.$nextTick(() => {
            self.dependingDetail = {
              ...response.data
            };
          });
        }
      } else {
        this.$message({
          type: "error",
          message: "暂无数据！"
        });
      }
    },
    async queryMedicalHistoryFun(medicalHistoryId, detail) {
      let self = this;
      let response = await queryMedicalHistory({
        medicalHistoryId: medicalHistoryId
      });
      if (response.code == 200 && response.data) {
        self.modelType = "dependingDetailDialog";
        if (response.data) {
          self.$nextTick(() => {
            self.dependingDetail = {
              ...detail,
              ...response.data
            };
          });
        } else {
          self.$nextTick(() => {
            self.dependingDetail = {
              ...detail
            };
          });
        }
      } else {
        this.$message({
          type: "error",
          message: "暂无数据！"
        });
      }
    }
    /* 获取订单信息  end */
  },
  filters: {
    patientNameLength: function(val) {
      if (val) {
        return val.length >= 5 ? val.substr(0, 4) + "..." : val;
      } else {
        return "暂无";
      }
    }
  },
  watch: {
    "$store.state.common.STATE": function(val) {
      this.listFun();
    }
  }
};
</script>
<style scoped>
.box {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background-color: #fff;
  border-radius: 4px;
}

.Interrogation {
  background-color: #fff;
  padding: 40px;
  padding-bottom: 0;
  padding-top: 0px;
  box-sizing: border-box;
  min-height: calc(100vh - 60px - 40px - 63px);
  overflow: hidden;
}
.title {
  height: 60px;
  line-height: 60px;
  overflow: hidden;
  display: flex;
  align-items: center;
  width: 100%;
}
.content {
  overflow: hidden;
  min-height: calc(100vh - 60px - 40px - 63px - 110px);
}
.footer {
  height: 40px;
  position: relative;
  bottom: 0px;
  display: flex;
  justify-content: center;
}

.content {
  overflow: hidden;
  min-height: 62vh;
  margin-bottom: 60px;
}
.footer {
  height: 20px;
  position: relative;
  bottom: 20px;
  display: flex;
  justify-content: center;
}
/* 暂无数据 */
.noData {
  width: 100%;
  overflow: hidden;
  min-height: calc(100vh - 60px - 40px - 63px - 110px);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.noPatientImg {
  width: 200px;
  height: 200px;
}
.noPatient {
  font-size: 14px;
  font-family: MicrosoftYaHei;
  color: rgba(102, 102, 102, 1);
  margin-top: 16px;
}
.submitBtn {
  width: 60px;
  height: 30px;
  border-radius: 15px;
  text-align: center;
  border: 1px solid rgba(255, 95, 42, 1);
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(255, 95, 42, 1);
  line-height: 28px;
}
</style>
